//
//  MainTabBarController.swift
//  weibo
//
//  Created by 黄龙飞 on 15/11/22.
//  Copyright © 2015年 黄龙飞. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {
    @objc private func clickComposedButton(){
    print("dianwole")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
addChildViewControllers()
        setupComposedButton()
        
    }
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        //
        tabBar.bringSubviewToFront(composedButton)
    }
    private lazy var composedButton:UIButton=UIButton(
        imageName: "tabbar_compose_icon_add",
        backImageName: "tabbar_compose_button"
    )
    

}
extension MainTabBarController{
    private func setupComposedButton(){
    tabBar.addSubview(composedButton)
        let count=childViewControllers.count
        let w=tabBar.bounds.width/CGFloat(count)-1
        composedButton.frame=CGRectInset(tabBar.bounds, 2*w, 0)
        composedButton.addTarget(self, action: "clickComposedButton", forControlEvents: .TouchUpInside)
    }
    private func addChildViewControllers() {
        tabBar.tintColor=UIColor.orangeColor()
        addChildViewController(HomeViewController(),title:"首页",imageName:"tabbar_home")
        addChildViewController(MessageViewController(),title:"消息",imageName:"tabbar_message_center")
        addChildViewController(UIViewController())
        addChildViewController(DiscoverViewController(),title:"发现",imageName:"tabbar_discover")
        addChildViewController(ProfileViewController(),title:"我",imageName:"tabbar_profile")
    }
    private func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        vc.title=title
        vc.tabBarItem.image=UIImage(named: imageName)
        let nav=UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
}